<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.name" placeholder="姓名"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="getData">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="dataList" highlight-current-row v-loading="listLoading" style="width: 100%;">
			<el-table-column type="index" width="60">
			</el-table-column>
			<el-table-column prop="name" label="任务名称" width="120" sortable>
			</el-table-column>
			<el-table-column prop="describe" label="任务描述" width="400" sortable>
			</el-table-column>
			<el-table-column prop="data_brief" label="数据简要说明" width="400" sortable>
			</el-table-column>
			<el-table-column label="操作" width="150">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">审核</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :total="total" style="float:right;">
			</el-pagination>
		</el-col>

		<!--编辑界面-->
		<el-dialog title="编辑" v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="80px" ref="editForm">
				<el-form-item label="任务名称" prop="name">
					<el-input v-model="editForm.name" auto-complete="off" disabled></el-input>
				</el-form-item>
				<el-form-item label="任务描述" prop="describe">
					<el-input v-model="editForm.describe" auto-complete="off" disabled></el-input>
				</el-form-item>
				<el-form-item label="数据简要" prop="describe">
					<el-input v-model="editForm.data_brief" auto-complete="off" disabled></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false" type="warning">审核不通过</el-button>
				<el-button type="primary" @click.native="editSubmit(true)" :loading="editLoading">审核通过</el-button>
			</div>
		</el-dialog>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getDataList, passData, preventData } from '../../api/api';

	export default {
		data() {
			return {
				filters: {
					name: ''
				},
				dataList: [],
				total: 0,
				page: 1,
				listLoading: false,

				editFormVisible: false,//编辑界面是否显示
				editLoading: false,
				//编辑界面数据
				editForm: {
					id: 0,
					name: '',
					describe: '',
					data_brief: '',
				},

			}
		},
		methods: {
			handleCurrentChange(val) {
				this.page = val;
				this.getTasks();
			},

			getData() {
				let para = {
					last_id: 0,
					data_type: 3,
				};
				this.listLoading = true;
				getDataList(para).then((res) => {
					this.dataList = res.data.data;
					this.listLoading = false;
				});
			},
			//显示编辑界面
			handleEdit: function (index, row) {
				this.editFormVisible = true;
				this.editForm = Object.assign({}, row);
			},
			//编辑
			editSubmit: function (station) {
				this.$confirm('确认提交吗？', '提示', {}).then(() => {
					this.editLoading = true;

					let para = Object.assign({}, this.editForm);
					para = {
						data_id: para.id,
					}
					if (station === true) {
						passData(para).then((res) => {
							this.editLoading = false;
							this.$message({
								message: '提交成功',
								type: 'success'
							});
							this.$refs['editForm'].resetFields();
							this.editFormVisible = false;
							this.getData();
						});
					} else {
						preventData(para).then((res) => {
							this.editLoading = false;
							this.$message({
								message: '提交成功',
								type: 'success'
							});
							this.$refs['editForm'].resetFields();
							this.editFormVisible = false;
							this.getData();
						});
					}
				});
			},
		},
		mounted() {
			this.getData();
		}
	}

</script>

<style scoped>

</style>
